/*
 * CastDRAndroid
 * Copyright (c) 2014 Christian Holm Christensen
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.cholm.media.castdr;// CastDRAndroid

import android.util.Log;

/**
 * Created by cholm on 4/4/14.
 */
public class LogUtils {
    /** Prefix on log entries */
    private static final String LOG_PREFIX = "cdr_";
    /** Length of static prefix */
    private static final int LOG_PREFIX_LENGTH = LOG_PREFIX.length();
    /** Maximum length of tags */
    private static final int MAX_LOG_TAG_LENGTH = 23;

    /**
     * Cannot make object of this class
     */
    private LogUtils() {
    }

    /**
     * Make a log TAG based on the a string
     *
     * @param str String for tag
     *
     * @return The created TAG
     */
    public static String makeLogTag(String str) {
        if (str.length() > MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH) {
            return LOG_PREFIX + str.substring(0, MAX_LOG_TAG_LENGTH - LOG_PREFIX_LENGTH - 1);
        }
        return LOG_PREFIX + str;
    }

    /**
     * Create a log tag based on class name
     *
     * WARNING: Don't use this when obfuscating class names with Proguard!
     */
    public static String makeLogTag(Class<?> cls) {
        return makeLogTag(cls.getSimpleName());
    }

    /**
     * Debug message
     *
     * @param tag The tag
     * @param message The message
     */
    @SuppressWarnings("unused")
    public static void LOGd(final String tag, String message) {
        if (BuildConfig.DEBUG || Log.isLoggable(tag, Log.DEBUG)) {
            Log.d(tag, message);
        }
    }

    /**
     * Debug message
     * @param tag TAG
     * @param message Message
     * @param cause Exception or the like
     */
    @SuppressWarnings("unused")
    public static void LOGd(final String tag, String message, Throwable cause) {
        if (BuildConfig.DEBUG || Log.isLoggable(tag, Log.DEBUG)) {
            Log.d(tag, message, cause);
        }
    }

    /**
     * Verbose message
     * @param tag TAG
     * @param message Message
     */
    public static void LOGv(final String tag, String message) {
        if (BuildConfig.DEBUG &&
                Log.isLoggable(tag, Log.VERBOSE)) {
            Log.v(tag, message);
        }
    }

    /**
     * Verbose message
     * @param tag TAG
     * @param message Message
     * @param cause Exception or the like
     */
    public static void LOGv(final String tag, String message, Throwable cause) {
        if (BuildConfig.DEBUG &&
                Log.isLoggable(tag, Log.VERBOSE)) {
            Log.v(tag, message, cause);
        }
    }

    /**
     * Information message
     * @param tag TAG
     * @param message Message
     */
    public static void LOGi(final String tag, String message) {
        Log.i(tag, message);
    }

    /**
     * Information message
     * @param tag TAG
     * @param message Message
     * @param cause Exception or the like
     */
    public static void LOGi(final String tag, String message, Throwable cause) {
        Log.i(tag, message, cause);
    }

    /**
     * Warning message
     * @param tag TAG
     * @param message Message
     */
    public static void LOGw(final String tag, String message) {
        Log.w(tag, message);
    }

    /**
     * Warning message
     * @param tag TAG
     * @param message Message
     * @param cause Exception or the like
     */
    public static void LOGw(final String tag, String message, Throwable cause) {
        Log.w(tag, message, cause);
    }

    /**
     * Error message
     * @param tag TAG
     * @param message Message
     */
    public static void LOGe(final String tag, String message) {
        Log.e(tag, message);
    }

    /**
     * Error message
     * @param tag TAG
     * @param message Message
     * @param cause Exception or the like
     */
    public static void LOGe(final String tag, String message, Throwable cause) {
        Log.e(tag, message, cause);
    }

}
